/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.library.web_layer.adminPages;

import cz.muni.fi.pa165.library.api.Available;
import cz.muni.fi.pa165.library.api.BookService;
import cz.muni.fi.pa165.library.api.UserService;
import cz.muni.fi.pa165.library.api.UserTO;
import cz.muni.fi.pa165.library.web_layer.ApplicationContextProvider;
import cz.muni.fi.pa165.library.web_layer.Login;
import cz.muni.fi.pa165.library.web_layer.adminPages.Book.ShowAllBook;
import cz.muni.fi.pa165.library.web_layer.Template;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

/**
 *
 * @author dulinka
 */
public class RegistrationLibrarianForm extends Template {
    private UserTO user;
    
    public RegistrationLibrarianForm(final PageParameters parameters){
        super(parameters);
        user = new UserTO();
        
        Form<?> form = new Form("form") {
            UserService userService = (UserService)ApplicationContextProvider.getApplicationContext().getBean("userService");
            @Override
            protected void onSubmit() {
                if (userService.findUserByEmail(user.getEmail())== null){
                   userService.createUser(user); 
                }
                setResponsePage(ShowAllBook.class);
            }
        };
        form.add(new TextField("firstName", new PropertyModel<String>(user, "firstName")).setRequired(true));
        form.add( new TextField("lastName", new PropertyModel<String>(user, "lastName")).setRequired(true));
        form.add(new TextField("email", new PropertyModel<String>(user, "email")).setRequired(true));
        form.add(new TextField( "password", new PropertyModel<String>(user, "password")).setRequired(true));
        add(form);
    }
}
